local guizhan = fk.CreateSkill {
  name = "ls__guizhan",
}

Fk:loadTranslationTable{
  ["ls__guizhan"] = "诡斩",
  [":ls__guizhan"] = "回合开始时，你可扣置一张手牌，视为使用【杀】，此【杀】被抵消/造成伤害时，你将扣置的牌置入弃牌堆，若不为/为【杀】，此【杀】依然造成伤害/造成的伤害+1。",
  ["#ls__guizhan-prompt"] = "诡斩：你可扣置一张手牌，视为使用【杀】",

  ["$ls__guizhan1"] = "潜身伏首，袭贼建功！",
  ["$ls__guizhan2"] = "掩其不备，叛贼授首！",
}

guizhan:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      skill_name = guizhan.name,
      include_equip = false,
      pattern = ".",
      prompt = "#ls__guizhan-prompt",
      cancelable = true,
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    player:addToPile("ls__guizhan", cards, false, guizhan.name)
    local params = {
      name = "slash",
      skill_name = guizhan.name,
    }
    if not room:askToUseVirtualCard(player, params) then
      room:moveCardTo(player:getPile("ls__guizhan"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, guizhan.name, nil, true)
    end
  end,
})

guizhan:addEffect(fk.CardEffectCancelledOut, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(guizhan.name) and data.from == player and data.card.trueName == "slash" and data.card.skillName == guizhan.name then
      return #player:getPile("ls__guizhan") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:getCardById(player:getPile("ls__guizhan")[1])
    room:moveCardTo(player:getPile("ls__guizhan"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, guizhan.name, nil, true)
    if card.trueName ~= "slash" then
      data.isCancellOut = false
    end
  end,
})

guizhan:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(guizhan.name) and target == player and data.card and data.card.skillName == guizhan.name then
      return #player:getPile("ls__guizhan") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:getCardById(player:getPile("ls__guizhan")[1])
    room:moveCardTo(player:getPile("ls__guizhan"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, guizhan.name, nil, true)
    if card.trueName == "slash" then
      data:changeDamage(1)
    end
  end,
})

guizhan:addEffect(fk.CardUseFinished, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(guizhan.name) and target == player and data.card.skillName == guizhan.name then
      return #player:getPile("ls__guizhan") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("ls__guizhan"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, guizhan.name, nil, true)
  end,
})

return guizhan